package org.csu.mypetstorecmsapi.persistence;

import jakarta.transaction.Transactional;
import org.csu.mypetstorecmsapi.domain.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProductDao extends JpaRepository<Product, Integer> {

    @Transactional
    @Modifying
    @Query(value = "delete from product where category =?1", nativeQuery = true)
    void deleteByCategoryId(String categoryId);

    @Modifying
    @Query(value = "select * from product where category =?1", nativeQuery = true)
    List<Product> findByCategoryId(String categoryId);
}
